//
//  InvestTableViewCell.m
//  huien
//
//  Created by yiban on 2017/5/26.
//  Copyright © 2017年 lcb. All rights reserved.
//

#import "InvestTableViewCell.h"
#import "UIButton+YBAdd.h"

#import "ModuleModel.h"
@interface InvestTableViewCell()
{
    
}
@property(nonatomic,strong)UILabel*tagLabelK;
@property(nonatomic,strong)UILabel*titleLabelK;
@property(nonatomic,strong)UILabel*payLabelK;
@property(nonatomic,strong)UILabel*nsyLabelK;
@property(nonatomic,strong)UILabel*nsyLabelV;
@property(nonatomic,strong)UILabel*jkqxLabelK;
@property(nonatomic,strong)UILabel*jkqxLabelV;
@property(nonatomic,strong)UILabel*jkjeLabelK;
@property(nonatomic,strong)UILabel*jkjeLabelV;
@property(nonatomic,strong)UIButton*touziBtn;

@property(nonatomic,strong)UIProgressView*progressview;
@property(nonatomic,strong)UILabel*processLabelV;
@property(nonatomic,strong)UIImageView *progressImage;
@end
@implementation InvestTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    self.data =model;
    self.indexPath=indexPath;
    InvestmentsModel *commentModel = (InvestmentsModel*)model;
    BOOL isFull = YES;
    if([commentModel.investType isEqualToString:@"热门标"] ||[commentModel.investType isEqualToString:@"新手标"] )
    {
        isFull = NO;
    }
    //
    NSString *investType =commentModel.investType;
    CGFloat typewight1 = [investType widthForFont:self.tagLabelK.font];
    if (isFull) {
        self.tagLabelK.backgroundColor = UIColorFromRGB(0x37b7b5);
        self.tagLabelK.layer.cornerRadius =4.0;
    }else{
        self.tagLabelK.backgroundColor = UIColorFromRGB(0xff7676);
        self.tagLabelK.layer.cornerRadius =4.0;
    }
    
    if([investType isEqualToString:@"新手标"] )
    {
        self.tagLabelK.frame =CGRectMake(-8, 10, typewight1+30, 22);
        self.tagLabelK.layer.cornerRadius =8.0;
        self.tagLabelK.textAlignment = NSTextAlignmentCenter;
    }else{
        if (investType==nil || investType.length==0) {
            self.tagLabelK.frame=CGRectZero;
        }else{
            self.tagLabelK.frame =CGRectMake(10, 10, typewight1+10, 22);
            self.tagLabelK.textAlignment = NSTextAlignmentCenter;
        }
        
    }
    self.tagLabelK.text =investType;
    
    //
    NSString *title =commentModel.investTitle;
    CGFloat wight = [title widthForFont:self.titleLabelK.font];
    if (wight>SCREEN_WIDTH/2) {
        wight=SCREEN_WIDTH/2;
    }
    self.titleLabelK.frame =CGRectMake(10, self.tagLabelK.frame.origin.y+self.tagLabelK.frame.size.height+10, wight, 20);
    self.titleLabelK.text = title;
    //
    NSString *repayment =commentModel.repayment;
    CGFloat wight1 = [repayment widthForFont:self.payLabelK.font];
    self.payLabelK.frame =CGRectMake(self.titleLabelK.frame.origin.x+self.titleLabelK.frame.size.width+10, self.titleLabelK.frame.origin.y, wight1+10, 20);
    if (isFull) {
        self.payLabelK.textColor = UIColorFromRGB(0x37b7b5);
        self.payLabelK.layer.borderColor=UIColorFromRGB(0x37b7b5).CGColor;
    }else{
        self.payLabelK.textColor = UIColorFromRGB(0xeb786b);
        self.payLabelK.layer.borderColor=UIColorFromRGB(0xeb786b).CGColor;
    }
    self.payLabelK.text = repayment;
    //
   
    CGFloat detailWight =(SCREEN_WIDTH-50)/4;
    if(isFull==NO)
    {
        detailWight =(SCREEN_WIDTH-50)/4;
    }else{
        detailWight =(SCREEN_WIDTH-50)/3;
    }
    NSMutableArray *detailModel =commentModel.details;
    InvestmentsDetailsModel *mdModel0 = [detailModel objectAtIndex:0];
    CGFloat h = self.titleLabelK.frame.origin.y+self.titleLabelK.frame.size.height+10;
    self.nsyLabelK.frame =CGRectMake(10, h, detailWight, 20);
    self.nsyLabelK.text =mdModel0.name;
    
    self.nsyLabelV.frame =CGRectMake(self.nsyLabelK.frame.origin.x, self.nsyLabelK.frame.origin.y+self.nsyLabelK.frame.size.height+5, self.nsyLabelK.frame.size.width, 20);
    self.nsyLabelV.text =mdModel0.value;
    //
    InvestmentsDetailsModel *mdModel1 = [detailModel objectAtIndex:1];
    self.jkqxLabelK.frame =CGRectMake(self.nsyLabelK.frame.origin.x+self.nsyLabelK.frame.size.width+10, h, detailWight, 20);
    self.jkqxLabelK.text=mdModel1.name;
    self.jkqxLabelV.frame =CGRectMake(self.jkqxLabelK.frame.origin.x, self.jkqxLabelK.frame.origin.y+self.jkqxLabelK.frame.size.height+5, self.jkqxLabelK.frame.size.width, 20);
    self.jkqxLabelV.text=mdModel1.value;
    //
    InvestmentsDetailsModel *mdModel2 = [detailModel objectAtIndex:2];
    self.jkjeLabelK.frame =CGRectMake(self.jkqxLabelK.frame.origin.x+self.jkqxLabelK.frame.size.width+10, h, detailWight, 20);
    self.jkjeLabelK.text=mdModel2.name;
    self.jkjeLabelV.frame =CGRectMake(self.jkjeLabelK.frame.origin.x, self.jkjeLabelK.frame.origin.y+self.jkjeLabelK.frame.size.height+5, self.jkjeLabelK.frame.size.width, 20);
    self.jkjeLabelV.text=mdModel2.value;
    //
    if(isFull==NO)
    {
         self.touziBtn.frame =CGRectMake(SCREEN_WIDTH-80, self.jkjeLabelK.frame.origin.y+3, detailWight-20, 37);
    }else{
        self.touziBtn.frame =CGRectZero;
    }
    //
    NSDictionary *process =commentModel.progress;
    CGFloat rate = [process[@"rate"] floatValue];
    self.progressImage.frame =CGRectMake(10, self.jkjeLabelV.frame.origin.y+self.jkjeLabelV.frame.size.height+10, 40, 20);
    self.processLabelV.frame =CGRectMake(0, 0, self.progressImage.frame.size.width, self.progressImage.frame.size.height);
    self.processLabelV.text =[NSString stringWithFormat:@"%.f%@",rate*100,@"%"];
    if (isFull==NO) {
          self.progressview.frame =CGRectMake(self.progressImage.frame.origin.x+self.progressImage.frame.size.width+10, self.progressImage.frame.origin.y+(20-2)/2, SCREEN_WIDTH-100-self.touziBtn.frame.size.width, 2);
    }else{
          self.progressview.frame =CGRectMake(self.progressImage.frame.origin.x+self.progressImage.frame.size.width+10, self.progressImage.frame.origin.y+(20-2)/2, SCREEN_WIDTH-80, 2);
    }
  
    self.progressview.progress = rate;
    //
}
+(CGFloat)returnCellHeight:(id)model
{
    InvestmentsModel *commentModel = (InvestmentsModel*)model;
    if (commentModel.investType==nil ||commentModel.investType.length==0) {
        return 132;
    }
    return 164;
}
-(void)dealloc
{
    [LcbLog log:@"ModuleTableViewCell--------->dealloc"];
}
-(UILabel*)tagLabelK
{
    if (!_tagLabelK) {
        _tagLabelK = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _tagLabelK.font = [UIFont systemFontOfSize:12];
        _tagLabelK.textColor = UIColorFromRGB(0xffffff);
        _tagLabelK.textAlignment = NSTextAlignmentCenter;
        _tagLabelK.backgroundColor = UIColorFromRGB(0xff7676);
        _tagLabelK.lineBreakMode = NSLineBreakByTruncatingTail;
        _tagLabelK.numberOfLines = 1;
        _tagLabelK.layer.masksToBounds=YES;
        _tagLabelK.layer.cornerRadius =4.0;
        [self addSubview:_tagLabelK];
    }
    return _tagLabelK;
}
-(UILabel*)titleLabelK
{
    if (!_titleLabelK) {
        _titleLabelK = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _titleLabelK.font = [UIFont systemFontOfSize:13];
        _titleLabelK.textColor = UIColorFromRGB(0x666666);
        _titleLabelK.textAlignment = NSTextAlignmentLeft;
        _titleLabelK.backgroundColor = [UIColor clearColor];
        _titleLabelK.lineBreakMode = NSLineBreakByTruncatingTail;
        _titleLabelK.numberOfLines = 1;
        [self addSubview:_titleLabelK];
    }
    return _titleLabelK;
}
-(UILabel*)payLabelK
{
    if (!_payLabelK) {
        _payLabelK = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _payLabelK.font = [UIFont systemFontOfSize:13];
        _payLabelK.textColor = UIColorFromRGB(0xff7676);
        _payLabelK.textAlignment = NSTextAlignmentCenter;
        _payLabelK.backgroundColor = [UIColor clearColor];
        _payLabelK.lineBreakMode = NSLineBreakByTruncatingTail;
        _payLabelK.numberOfLines = 1;
        _payLabelK.layer.cornerRadius=2.5;
        _payLabelK.layer.borderWidth=1;
        _payLabelK.layer.borderColor=UIColorFromRGB(0xeb786b).CGColor;
        [self addSubview:_payLabelK];
    }
    return _payLabelK;
}
-(UILabel*)nsyLabelK
{
    if (!_nsyLabelK) {
        _nsyLabelK = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _nsyLabelK.font = [UIFont systemFontOfSize:12];
        _nsyLabelK.textColor = UIColorFromRGB(0x999999);
        _nsyLabelK.textAlignment = NSTextAlignmentLeft;
        _nsyLabelK.backgroundColor = [UIColor clearColor];
        _nsyLabelK.lineBreakMode = NSLineBreakByTruncatingTail;
        _nsyLabelK.numberOfLines = 1;
        [self addSubview:_nsyLabelK];
    }
    return _nsyLabelK;
}
-(UILabel*)nsyLabelV
{
    if (!_nsyLabelV) {
        _nsyLabelV = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _nsyLabelV.font = [UIFont systemFontOfSize:18];
        _nsyLabelV.textColor = UIColorFromRGB(0xeb9a1a);
        _nsyLabelV.textAlignment = NSTextAlignmentLeft;
        _nsyLabelV.backgroundColor = [UIColor clearColor];
        _nsyLabelV.lineBreakMode = NSLineBreakByTruncatingTail;
        _nsyLabelV.numberOfLines = 1;
        [self addSubview:_nsyLabelV];
    }
    return _nsyLabelV;
}
-(UILabel*)jkqxLabelK
{
    if (!_jkqxLabelK) {
        _jkqxLabelK = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _jkqxLabelK.font = [UIFont systemFontOfSize:12];
        _jkqxLabelK.textColor = UIColorFromRGB(0x999999);
        _jkqxLabelK.textAlignment = NSTextAlignmentCenter;
        _jkqxLabelK.backgroundColor = [UIColor clearColor];
        _jkqxLabelK.lineBreakMode = NSLineBreakByTruncatingTail;
        _jkqxLabelK.numberOfLines = 1;
        [self addSubview:_jkqxLabelK];
    }
    return _jkqxLabelK;
}
-(UILabel*)jkqxLabelV
{
    if (!_jkqxLabelV) {
        _jkqxLabelV = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _jkqxLabelV.font = [UIFont systemFontOfSize:14];
        _jkqxLabelV.textColor = UIColorFromRGB(0x333333);
        _jkqxLabelV.textAlignment = NSTextAlignmentCenter;
        _jkqxLabelV.backgroundColor = [UIColor clearColor];
        _jkqxLabelV.lineBreakMode = NSLineBreakByTruncatingTail;
        _jkqxLabelV.numberOfLines = 1;
        [self addSubview:_jkqxLabelV];
    }
    return _jkqxLabelV;
}
-(UILabel*)jkjeLabelK
{
    if (!_jkjeLabelK) {
        _jkjeLabelK = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _jkjeLabelK.font = [UIFont systemFontOfSize:12];
        _jkjeLabelK.textColor = UIColorFromRGB(0x999999);
        _jkjeLabelK.textAlignment = NSTextAlignmentRight;
        _jkjeLabelK.backgroundColor = [UIColor clearColor];
        _jkjeLabelK.lineBreakMode = NSLineBreakByTruncatingTail;
        _jkjeLabelK.numberOfLines = 1;
        [self addSubview:_jkjeLabelK];
    }
    return _jkjeLabelK;
}
-(UILabel*)jkjeLabelV
{
    if (!_jkjeLabelV) {
        _jkjeLabelV = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _jkjeLabelV.font = [UIFont systemFontOfSize:14];
        _jkjeLabelV.textColor = UIColorFromRGB(0x333333);
        _jkjeLabelV.textAlignment = NSTextAlignmentRight;
        _jkjeLabelV.backgroundColor = [UIColor clearColor];
        _jkjeLabelV.lineBreakMode = NSLineBreakByTruncatingTail;
        _jkjeLabelV.numberOfLines = 1;
        [self addSubview:_jkjeLabelV];
    }
    return _jkjeLabelV;
}
-(UIButton*)touziBtn
{
    if (!_touziBtn) {
        _touziBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _touziBtn.backgroundColor =UIColorFromRGB(0x4d8fcb);
        _touziBtn.tag=1;
        _touziBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_touziBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_touziBtn setTitle:@"投标" forState:UIControlStateNormal];
        [_touziBtn addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_touziBtn];
        _touziBtn.layer.cornerRadius=5;
    }
    return _touziBtn;
}
-(UIImageView*)progressImage
{
    if (!_progressImage) {
        _progressImage =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 32)];
        _progressImage.image = [UIImage imageNamed:@"bg_process"];
        [self addSubview:_progressImage];
    }
    return _progressImage;
}
-(UILabel*)processLabelV
{
    if (!_processLabelV) {
        _processLabelV = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 20)];
        _processLabelV.text = @"60%";
        _processLabelV.font = [UIFont systemFontOfSize:12];
        _processLabelV.textColor = UIColorFromRGB(0xffffff);
        _processLabelV.textAlignment = NSTextAlignmentCenter;
        _processLabelV.backgroundColor = [UIColor clearColor];
        _processLabelV.lineBreakMode = NSLineBreakByTruncatingTail;
        _processLabelV.numberOfLines = 1;
        [self.progressImage addSubview:_processLabelV];
    }
    return _processLabelV;
}
-(UIProgressView*)progressview
{
    if (!_progressview) {
        _progressview= [[UIProgressView alloc]initWithFrame:CGRectMake(0,20,320,2)];
        _progressview.progressViewStyle=UIProgressViewStyleDefault;
        _progressview.trackTintColor= UIColorFromRGB(0xe5e5e5);
        _progressview.progressTintColor= UIColorFromRGB(0xeb9a1a);
        _progressview.progress=0.5;
        
        [self addSubview:_progressview];
        
    }
    return _progressview;
}
-(void)clickEvent:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    if (self.actionBlock) {
        self.actionBlock(BEventType_Module,self,btn.tag,self.data,self.indexPath);
    }
}
@end
